load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test_suite")

package(default_visibility = ["//visibility:public"])

DEPENDENCIES = [
    # Keep sorted.
    "//rs/ledger_suite/icp:icp_ledger",
    "//rs/ledger_suite/icp/ledger",
    "//rs/ledger_suite/icp/test_utils",
    "//rs/rosetta-api/icp:rosetta-api",
    "//rs/rosetta-api/icrc1/client:ic-icrc-rosetta-client",
    "@crate_index//:candid",
    "@crate_index//:tempfile",
    "@crate_index//:tokio",
    "@crate_index//:url",
]

DEV_DEPENDENCIES = [
    # Keep sorted.
    ":rosetta-integration-tests-lib",
    "//packages/icrc-ledger-types:icrc_ledger_types",
    "//packages/pocket-ic:pocket-ic",
    "//rs/nns/constants",
    "//rs/rosetta-api/common/rosetta_core:rosetta-core",
    "//rs/rosetta-api/icp/test_utils/sender_canister:ic_sender_canister_lib",
    "//rs/rosetta-api/icrc1:ic-icrc-rosetta",
    "//rs/test_utilities/load_wasm",
    "@crate_index//:anyhow",
    "@crate_index//:ic-agent",
    "@crate_index//:num-traits",
    "@crate_index//:serde",
]

rust_library(
    name = "rosetta-integration-tests-lib",
    testonly = True,
    srcs = glob(["src/**/*.rs"]),
    crate_name = "icp_rosetta_integration_tests",
    proc_macro_deps = [
    ],
    version = "0.1.0",
    deps = DEPENDENCIES,
)

rust_test_suite(
    name = "rosetta-integration",
    srcs = ["tests/tests.rs"],
    data = [
        "//rs/canister_sandbox",
        "//rs/canister_sandbox:sandbox_launcher",
        "//rs/ledger_suite/icp/ledger:ledger-canister-wasm",
        "//rs/pocket_ic_server:pocket-ic-server",
        "//rs/rosetta-api/icp:ic-rosetta-api-rosetta-blocks",
        "//rs/rosetta-api/icp/test_utils/sender_canister:ic-sender-canister",
        "@mainnet_canisters//:ledger.wasm.gz",
    ],
    env = {
        "CANISTER_LAUNCHER": "$(rootpath //rs/canister_sandbox)",
        "LEDGER_CANISTER_WASM_PATH": "$(rootpath //rs/ledger_suite/icp/ledger:ledger-canister-wasm)",
        "POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)",
        "ROSETTA_PATH": "$(rootpath //rs/rosetta-api/icp:ic-rosetta-api-rosetta-blocks)",
        "RUST_TEST_THREADS": "4",
        "SANDBOX_LAUNCHER": "$(rootpath //rs/canister_sandbox:sandbox_launcher)",
        "IC_SENDER_CANISTER_WASM_PATH": "$(rootpath //rs/rosetta-api/icp/test_utils/sender_canister:ic-sender-canister)",
        "ICP_LEDGER_DEPLOYED_VERSION_WASM_PATH": "$(rootpath @mainnet_canisters//:ledger.wasm.gz)",
    },
    # The test is critical to get resources timely and therefore fails sometimes when run on heavily loaded node.
    # TODO(IDX-2225): reconsider when we will use Remote Execution.
    flaky = True,  # flakiness rate of over 2% over the month from 2025-02-11 till 2025-03-11.
    proc_macro_deps = [
    ],
    tags = ["cpu:4"],
    deps = DEPENDENCIES + DEV_DEPENDENCIES,
)
